<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/include/taglib.jsp"%>
<html>
<head>
<meta charset="UTF-8">
<title>我的账户-实名认证</title>
<jsp:include page="/include/wchat/head.jsp"></jsp:include>
<link type="text/css" rel="stylesheet" href="/v2/wchat/resrc/css/account.css">
</head>
<body>
<div id="header"> <a href="javascript:history.go(-1);" class="backto">返回</a>
  <div class="title-sub">实名认证</div>
</div>
<div id="wrap">
  <div class="itip">为保证您的账户安全,您需要先进行实名认证才能进行充值投资。</div>
  <div class="link-touch">
    <ul class="items">
      <li>
        <label class="txt">姓名</label>
        <input type="text" id="realName" class="input" maxlength="16" placeholder="请输入您的真实姓名">
      </li>
      <li>
        <label class="txt">身份证</label>
        <input type="text" id="idCardNo" class="input" maxlength="18" placeholder="请输入您的身份证号">
      </li>
    </ul>
    <div id="errorTip" class="vtip errs"></div>
  </div>
  <div class="operate-button"> <a href="javascript:realNameAuthen();" class="btn" id="realNameAuthenBt">实名认证</a> </div>
</div>



<jsp:include page="/include/wchat/footer.jsp"></jsp:include>





<script type="text/javascript">
//检查身份证号码
function checkIdCardNo(){
    var cardno = $("#idCardNo").val();
    var reg = /^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/;
    var re = new RegExp(reg);
    var idCardNoTip = $("#errorTip");
    if(cardno == "" || cardno.length == 0 ){
        idCardNoTip.html("请输入身份证号码").show();
        return false;
    }else if(!re.test(cardno)){
        idCardNoTip.html("身份证号可能有误，请检查后再进行认证").show();
        return false;   
    }else{
        return true;
    }
}

//检查姓名
function checkRealName(){
    var realName = $("#realName").val();
    var realNameTip = $("#errorTip");
    var chinese = "^[\\u4e00-\\u9fa5]+$";
    var cn = new RegExp(chinese);
    if(realName == "" || realName.length == 0 ){
        realNameTip.html("请输入姓名").show();
        return false;
    }
    else if(!cn.test(realName)){
        realNameTip.html('<i class="icons reg-error"></i>请输入中文').show();
        return false;
    }
    else{
        return true;
    }
}

//实名认证
function realNameAuthen(){
	if(checkRealName()&& checkIdCardNo()){
		var param = {};
    	param["paramMap.cardId"] = $.trim($("#idCardNo").val());
    	param["paramMap.realName"] = $.trim($("#realName").val());
		$.ajax({
			type:'POST',
			url: environment.basePath+"/checkUserIDCard.do",
			data: param,
			beforeSend:function(){
				 $("#realNameAuthenBt").html("认证中...").addClass("gbtn-disabled");
			},
			success: function(data){
				if(data == 3){
					 window.location.href =environment.basePath+"/wchatRealNameAuthen3.do";
				}else{
					$("#errorTip").html(getResultMsg(data)).show();
				}
				$("#realNameAuthenBt").html("认证").removeClass("gbtn-disabled");
			},
			error: function(){
				$("#errorTip").html("认证失败，请稍后再试").show();
				$("#realNameAuthenBt").html("认证").removeClass("gbtn-disabled");
			}
		});	
	}	   
}

function getResultMsg(data){
    switch(data){
    case 40004: return "姓名信息有误，请核实！"; break;
    case 4: return "该用户已经认证，不能重复认证"; break;
    case 3: return "认证成功"; break;
    case 2: return "认证失败，认证服务忙，请稍后操作!"; break;
    case 1: return "库中无此号，请到户籍所在地核实"; break;
    default: return "认证失败，认证服务忙，请稍后操作!"; break;
    }
}
</script>
</body>
</html>